package com.lkd.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lkd.entity.SkuClass;
import com.lkd.mapper.SkuCLassMapper;
import com.lkd.result.PageBean;
import com.lkd.service.SkuClassService;
import com.lkd.vo.SkuClassVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SkuClassServiceImpl implements SkuClassService {
    @Autowired
    private SkuCLassMapper skuCLassMapper;

    @Override
    public void save(SkuClass skuClass) {
        skuClass.setParentId(0);    //数据库0.先给个0
        skuCLassMapper.insert(skuClass);
    }

    @Override
    public PageBean<SkuClass> pageConditonQuerySkuClass(Integer pageIndex, Integer pageSize, String className) {
        PageHelper.startPage(pageIndex, pageSize);
        Page<SkuClass> page = (Page<SkuClass>) skuCLassMapper.selectPage(className);
        Long totalPage = (long) page.getPages();
        return new PageBean<SkuClass>(pageIndex, pageSize, totalPage, page.getTotal(), page.getResult());
    }

    @Override
    public SkuClassVo getById(Integer classId) {
        SkuClass skuClass = skuCLassMapper.selectById(classId);
        return BeanUtil.toBean(skuClass, SkuClassVo.class);
    }

    @Override
    public void updateById(SkuClass skuClass) {
        skuCLassMapper.updateById(skuClass);
    }

    @Override
    public void deleteById(String classId) {
        skuCLassMapper.deleteById(classId);
    }
}